package com.czjtxy.extraTerm.controller.usermodule;

import com.czjtxy.extraTerm.entity.DO.Tuser;
import com.czjtxy.extraTerm.server.UserService;
import com.czjtxy.extraTerm.serverImpl.UserServiceImpl;
import com.czjtxy.extraTerm.util.Util;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

/**
 * @program: staff-house
 * @author: MingYi
 * @create: 2021/07/05 01:05
 */
@WebServlet(name = "SelectUserServlet", value = "/SelectUserServlet")
public class SelectUserServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Tuser tuser = new Tuser();
        tuser.setStatus(Util.stringToInt(req.getParameter("status")));
        tuser.setUserName(req.getParameter("username"));
        UserService userService = new UserServiceImpl();
        List<Tuser> tusers = null;
        try {
            tusers = userService.getPart(tuser);
            for(Tuser tuser1 : tusers){
                System.out.println(tuser1);
            }
            req.setAttribute("tusers",tusers);
        } catch (SQLException | ClassNotFoundException throwables) {
            throwables.printStackTrace();
        }
        req.getRequestDispatcher("user/user.jsp").forward(req, resp);
    }
}
